package ioc

import (
	"gitee.com/flycash/ai-gateway-demo/internal/repository"
	"gitee.com/flycash/ai-gateway-demo/internal/service/llm"
	"gitee.com/flycash/ai-gateway-demo/internal/service/llm/platform/ali_deepseek"
	"gitee.com/flycash/ai-gateway-demo/internal/service/llm/platform/facade"
	"gitee.com/flycash/ai-gateway-demo/internal/service/llm/platform/zhipu"
	"github.com/gotomicro/ego/core/econf"
)

func InitPlatform(taskRepo repository.AsyncTaskRepo, repo repository.PromptConfigRepo) llm.Service {
	type aiConfig struct {
		ApiKey string `json:"apiKey"`
	}
	var alicfg aiConfig
	err := econf.UnmarshalKey("ali", &alicfg)
	if err != nil {
		panic(err)
	}
	var zhipucfg aiConfig
	err = econf.UnmarshalKey("zhipu", &zhipucfg)
	if err != nil {
		panic(err)
	}
	return facade.NewService(map[string]llm.Service{
		"ali":   ali_deepseek.NewService(alicfg.ApiKey, repo, taskRepo),
		"zhipu": zhipu.NewService(zhipucfg.ApiKey, repo, taskRepo),
	}, ali_deepseek.NewService(alicfg.ApiKey, repo, taskRepo))
}
